package com.gsi.webstore.platform.storefront.internal.shipping;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.Set;

import com.gsi.webstore.platform.storefront.capi.order.GSILineItemCtnrBO;
import com.gsi.webstore.platform.storefront.capi.order.GSIProductLineItemBO;
import com.gsi.webstore.platform.storefront.capi.shipping.GSIShippingBucketBO;
import com.gsi.webstore.platform.storefront.internal.order.GSIProductLineItemBOImpl;
import com.intershop.component.address.capi.AddressBO;
import com.intershop.component.region.capi.region.Region;
import com.intershop.component.shipping_data.capi.shippingmethod.ShippingMethod;
import com.intershop.sellside.appbase.b2c.capi.calculation.LineItemCtnrCalculationResultView;
import com.intershop.sellside.appbase.b2c.capi.order.CostInformationBO;
import com.intershop.sellside.appbase.b2c.capi.order.LineItemCtnrContext;
import com.intershop.sellside.appbase.b2c.capi.order.LineItemMessage;
import com.intershop.sellside.appbase.b2c.capi.order.PackSlipMessageLineItemBO;
import com.intershop.sellside.appbase.b2c.capi.order.ProductLineItemBO;
import com.intershop.sellside.appbase.b2c.capi.order.ServiceLineItemBO;
import com.intershop.sellside.appbase.b2c.capi.shipping.ShippingBucketBO;

public class GSIShippingBucketBOImpl implements GSIShippingBucketBO
{
    private ShippingBucketBO _delegate;
    private GSILineItemCtnrBO _parent;
    private LineItemCtnrContext _context;
    private LineItemCtnrCalculationResultView _calculationResultView;

    public GSIShippingBucketBOImpl(ShippingBucketBO bucket, GSILineItemCtnrBO parent, LineItemCtnrContext context,
                    final LineItemCtnrCalculationResultView calculationResultView)
    {
        _delegate = bucket;
        _parent = parent;
        _context = context;
        _calculationResultView = calculationResultView;
    }

    @Override
    public PackSlipMessageLineItemBO createPackSlipMessage(LineItemMessage arg0)
    {
        return _delegate.createPackSlipMessage(arg0);
    }

    @Override
    public String getId()
    {
        return _delegate.getId();
    }

    @Override
    public CostInformationBO getOverride()
    {
        return _delegate.getOverride();
    }

    @Override
    public PackSlipMessageLineItemBO getPackSlipMessage()
    {
        return _delegate.getPackSlipMessage();
    }

    @Override
    public Collection<? extends GSIProductLineItemBO> getProductLineItemBOs()
    {
        Collection<? extends ProductLineItemBO> pliBOs = _delegate.getProductLineItemBOs();
        
        if (pliBOs != null)
        {
            List<GSIProductLineItemBO> gsiPliBOs = new ArrayList<GSIProductLineItemBO>();
            
            for (ProductLineItemBO pliBO : pliBOs)
            {
                gsiPliBOs.add(createProductLineItemBO(pliBO));
            }
            
            return gsiPliBOs;
        }
        
        return null;
    }

    @Override
    public Collection<? extends GSIProductLineItemBO> getAllProductLineItemBOs()
    {
        Collection<? extends ProductLineItemBO> pliBOs = _delegate.getAllProductLineItemBOs();
        
        if (pliBOs != null)
        {
            List<GSIProductLineItemBO> gsiPliBOs = new ArrayList<GSIProductLineItemBO>();
            
            for (ProductLineItemBO pliBO : pliBOs)
            {
                gsiPliBOs.add(createProductLineItemBO(pliBO));
            }
            
            return gsiPliBOs;
        }
        
        return null;
    }

    @Override
    public String getPurchaseCurrencyCode()
    {
        return _delegate.getPurchaseCurrencyCode();
    }

    @Override
    public Set<Region> getRegions()
    {
        return _delegate.getRegions();
    }

    @Override
    public Date getRequestedDeliveryDate()
    {
        return _delegate.getRequestedDeliveryDate();
    }

    @Override
    public ShippingMethod getSelectedShippingMethod()
    {
        return _delegate.getSelectedShippingMethod();
    }

    @Override
    public ServiceLineItemBO getServiceLineItemBO()
    {
        return _delegate.getServiceLineItemBO();
    }

    @Override
    public AddressBO getShipToAddress()
    {
        return _delegate.getShipToAddress();
    }

    @Override
    public String getShippingInstructions()
    {
        return _delegate.getShippingInstructions();
    }

    @Override
    public <T extends CostInformationBO> Collection<T> getSurcharges()
    {
        return _delegate.getSurcharges();
    }

    @Override
    public boolean hasPackSlipMessage()
    {
        return _delegate.hasPackSlipMessage();
    }

    @Override
    public boolean isEligibleForPackSlipMessaging()
    {
        return _delegate.isEligibleForPackSlipMessaging();
    }

    @Override
    public boolean isPackSlipMessagingEnabled()
    {
        return _delegate.isPackSlipMessagingEnabled();
    }

    @Override
    public boolean isShipAlone()
    {
        return _delegate.isShipAlone();
    }

    @Override
    public void removePackSlipMessage()
    {
        _delegate.removePackSlipMessage();

    }

    private GSIProductLineItemBO createProductLineItemBO(ProductLineItemBO pliBO)
    {
        return new GSIProductLineItemBOImpl(pliBO, _parent, _calculationResultView);
//        return (GSIProductLineItemBO) _context.getLineItemCtnrProxyFactory().createProductLineItemBO(this, pliBO, _context);
    }
}
